//
//  smcScroller.m
//  juhu
//
//	Copyright (C) 2007 Christian Martick, http://juhu-mac.blogspot.com
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.

#import "smcScroller.h"


@implementation smcScroller

- (id)initWithFrame:(NSRect)frameRect
{
	frameRect.origin.x += 100;
	self = [super initWithFrame: frameRect];
	if (self != nil) {
		 [self setArrowsPosition: NSScrollerArrowsNone];
		 sFlags.slotDrawn = 0;
	}
	return self;
}

- (void) drawRect: (NSRect) rect
{
	[[smcThemes generalWindowColor] set];
	//[[NSColor colorWithCalibratedWhite: 0.9 alpha: 1] set];
	NSRectFill(rect);
	
	//if knob in rect, redraw
	if (NSIntersectsRect( rect, [self rectForPart: NSScrollerKnob]))
		[self drawKnob];
}

- (void)drawKnob
{
	NSRect bgRect = [self rectForPart: NSScrollerKnob];

	bgRect.size.width -= 4;
	bgRect.origin.x += 2;

    int minX = NSMinX(bgRect);
    int midX = NSMidX(bgRect);
    int maxX = NSMaxX(bgRect);
    int minY = NSMinY(bgRect);
    int midY = NSMidY(bgRect);
    int maxY = NSMaxY(bgRect);
    float radius = 5; 
    NSBezierPath *bgPath = [NSBezierPath bezierPath];
    
    // Bottom edge and bottom-right curve
    [bgPath moveToPoint:NSMakePoint(midX, minY)];
    [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, minY) 
                                     toPoint:NSMakePoint(maxX, midY) 
                                      radius:radius];
    
    // Right edge and top-right curve
    [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, maxY) 
                                     toPoint:NSMakePoint(midX, maxY) 
                                      radius:radius];
    
    // Top edge and top-left curve
    [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(minX, maxY) 
                                     toPoint:NSMakePoint(minX, midY) 
                                      radius:radius];
    
    // Left edge and bottom-left curve
    [bgPath appendBezierPathWithArcFromPoint:bgRect.origin 
                                     toPoint:NSMakePoint(midX, minY) 
                                      radius:radius];
	//[[NSColor colorWithCalibratedWhite: 64/255.0 alpha:0.85] set];
	//[[NSColor colorWithCalibratedWhite: 0.5 alpha: 0.95]set];
    //[[NSColor colorWithCalibratedRed: 0.688 
	//	green: 0.876 blue: 0.347 alpha: 0.5] set];
    
	[[NSColor colorWithCalibratedWhite: 0.8 alpha: 1] set];
	[bgPath fill];
}



@end
